module MatchesHelper
  def point_spread(match,team)
    case match.bet_type
      when "total"
        if team == match.home_team
          "total over #{match.total_point}"
        else
          "total under #{match.total_point}"
        end
      else
        home_point_spread = away_point_spread = match.point_spread.to_f.abs.to_s
        if match.point_spread.to_f >= 0
          home_point_spread = "away team favored to win by " + home_point_spread + " points"
          away_point_spread = "-" + away_point_spread
        else
          home_point_spread = "home team favored to win by " + home_point_spread + " points"
          away_point_spread = "+" + away_point_spread
        end

        if match.point_spread.to_f == 0
          home_point_spread = "equal teams, no handicap"
        end

        if team == match.home_team
          content_tag(:span, home_point_spread ,:class=>"bet-spread")
        else
          content_tag(:span, away_point_spread ,:class=>"bet-spread")
        end
    end
  end

  def match_rss_content(match,type=:recent)
    html = %Q{
        #{match.home_team.displayed_name} #{plus_or_minus(match.point_spread)} vs.
        #{match.away_team.displayed_name} #{plus_or_minus(-match.point_spread)}
        starts in #{distance_of_time_in_words Time.now,match.begin_at}.
     }
     case type
     when :bet
       html << "#{match.bets_count} people have taken a side"
     when :comment
       html << "#{match.comment_count} people have commented"
     else
     end
     html
  end

  def match_rss_title(match)
    "#{match.home_team.displayed_name} vs. #{match.away_team.displayed_name}"
  end


end
